package com.sanery.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sanery.service.UserService;
import com.sanery.service.impl.UserServiceImpl;

@Controller
public class LoginController {
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		return "/login"; // 转发
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String login(String username, String password, HttpSession session) {
		UserService service = new UserServiceImpl();
		Integer id = service.getUserId(username, password);
		if (id == null) {
			return null;
		}
		session.setAttribute("userid", id); // 标志用户已登录
		return "redirect:/list"; // 重定向
	}
}
